package org.finesys.quartz.controller;

import java.util.Arrays;

import org.finesys.common.core.constants.RestApiConfig;
import org.finesys.common.core.module.R;
import org.finesys.common.log.core.annotation.LogAnnotation;
import org.finesys.common.log.core.enums.OperateType;
import org.finesys.quartz.entity.SysJobLog;
import org.finesys.quartz.service.SysJobLogService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@RestController("/jobLog")
@Tag(name = "定时任务执行日志")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysJobLogController {

    private final SysJobLogService sysJobLogService;

    /**
     * 查询定时任务日志数据
     */
    @PostMapping(RestApiConfig.PAGE)
    public R<?> findPage(Page<SysJobLog> page, SysJobLog sysJobLog) {
        return R.success(sysJobLogService.findPage(page, sysJobLog));
    }

    /**
     * 查询定时任务日志数据
     */
    @PostMapping(RestApiConfig.LIST)
    public R<?> findList(SysJobLog sysJobLog) {
        return R.success(sysJobLogService.findList(sysJobLog));
    }


    /**
     * 查询一条定时任务日志数据
     */
    @PostMapping(RestApiConfig.GET)
    public R<?> findById(SysJobLog sysJobLog) {
        return R.success(sysJobLogService.getOne(sysJobLog));
    }

    @DeleteMapping(RestApiConfig.DELETE)
    @LogAnnotation(title = "删除定时任务日志", operateType = OperateType.DELETE)
    public R<?> delete(Long[] ids) {
        return R.success(sysJobLogService.removeBatchByIds(Arrays.asList(ids)));
    }
}
